package com.github.permissiondog.cancanpbackend.servlet;

import com.github.permissiondog.cancanpbackend.request.ApplicationConfirmRequest;
import com.github.permissiondog.cancanpbackend.response.BaseResponse;
import com.github.permissiondog.cancanpbackend.service.ApplicationService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/applicant/application/confirm")
public class ApplicantConfirmServlet extends BaseServlet {
    /**
     * 确认申请
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        var body = bind(req, resp, ApplicationConfirmRequest.class);
        if (body == null)   return;
        try {
            ApplicationService.getInstance().confirmApplication(body.applicationId, userLoggedIn(req).getId());
            json(resp, BaseResponse.builder().ok(true).build());
        } catch (Exception e) {
            json(resp, BaseResponse.builder().ok(false).msg("确认失败").error(e.getMessage()).build());
        }
    }
}
